<template>
	<view class="app">
		<view class="price-box">
			<text>支付金额</text>
			<text class="price">{{info.payMoney}}</text>
		</view>

		<view class="pay-type-list">

			<view class="type-item b-b" @click="changePayType(1)">
				<uv-icon name="weixin-circle-fill" size="30" color="#36cb59"></uv-icon>
				<view class="con">
					<text class="tit">微信支付</text>
					<text>推荐使用微信支付</text>
				</view>
				<label class="radio">
					<radio value="" color=" #ff633d" :checked='payType == 1' />
					</radio>
				</label>
			</view>
			<!-- <view class="type-item b-b" @click="changePayType(2)">
				<text class="icon yticon icon-alipay"></text>
				<view class="con">
					<text class="tit">支付宝支付</text>
				</view>
				<label class="radio">
					<radio value="" color=" #ff633d" :checked='payType == 2' />
					</radio>
				</label>
			</view>
			<view class="type-item" @click="changePayType(3)">
				<text class="icon yticon icon-erjiye-yucunkuan"></text>
				<view class="con">
					<text class="tit">预存款支付</text>
					<text>可用余额 ¥198.5</text>
				</view>
				<label class="radio">
					<radio value="" color=" #ff633d" :checked='payType == 3' />
					</radio>
				</label>
			</view> -->
		</view>
		
		<text class="mix-btn" @click="confirm">确认支付</text>
	</view>
</template>

<script>
import { appletsWechatOrderPay,partnerAppletsWechatOrderPay,getPerformance,getUserSubmitFormDataList} from '../../utils/api.js';
	export default {
		data() {
			return {
				payType: 1,
				orderInfo: {},
				info:{},
				formData:{}
			};
		},
		computed: {
		
		},
		onLoad(options) {
			this.info = JSON.parse(decodeURIComponent(options.info));
			console.log(this.info);
		},
		onShow() {
			this.getFormDataList()
		},
		methods: {
			//选择支付方式
			changePayType(type) {
				this.payType = type;
			},
			getFormDataList() {
				let data = {
					page: 1
				};
				getUserSubmitFormDataList(data).then(res => {
					if (res.code == 200) {
						this.formDataList = res.body.list;
						let data = {
							fromDataId:this.formDataList[0].id,
						};
						getPerformance(data).then(res => {
							if (res.code == 200) {
								this.formData = res.body;
							}
						});
					}
				});
			},
			//确认支付
			confirm() {
				let data = {
					page: 1
				};
				getUserSubmitFormDataList(data)
				.then(res => {
					if (res.code == 200) {
						this.formDataList = res.body.list;
						let data = {
							fromDataId:this.formDataList[0].id,
						};
						getPerformance(data).then(res => {
							if (res.code == 200) {
								this.formData = res.body;
							}
						});
					}
				}).then(()=>{
					let postData = {
						client: '小程序',
						openId: uni.getStorageSync('__ddminiUserOpenid'),
						orderId: this.info.id,
						orderNo: this.info.orderNo,
						payMoney:this.info.payMoney,
						payWay: 1,
						extJson: 'AX000000001',
						performanceNumId:this.formData.id
					};
					console.log(postData, '微信支付');
					uni.showLoading({
						title: '支付准备中',
						mask: true
					});
					partnerAppletsWechatOrderPay(postData).then(res=>{
						if(res.code==200){
							// let payList=res.body
							// let data = res.body;
							// var RSA = require('@/utils/wxapp_rsa.js')
							// let paySign =
							// 	`${data.appid}\n${data.timestamp}\n${data.noncestr}\nprepay_id=${data.prepay_id}\n`
							// // 私钥、商户API证书下载后，私钥 apiclient_key.pem 的内容
							// let sikey = `-----BEGIN PRIVATE KEY-----
							// 			MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCkKmpbnA4QnZmD
							// 			OVLPPORVj6YNLW+kdc17raHgMng5FXVZ3D6ZxthYHgnJUMSGD82BdqVmOwOvkhwt
							// 			hyCl8gpEi5JOr/88UMlSEwrwQWhKFQFA4SpMW489H+yuQkcUKKHZYQgOGgEoFN8r
							// 			WvqYfhBgixxcoDlzcp4VKzCrM6yibD+BkVBcjRdrWFQhloQyR/Dc+HDAZsQYXlJi
							// 			moUGeYq/BDircT8Vfs8wB3fTx7FoBqfbvkposv+VjjijEAhCR6VRaV7MKPTR4nof
							// 			fo7gHcTg6CGlQaepfwOF4rDmZPFVQXIgphAF17OGUTbw45jpAplWLzh3XYdNvawU
							// 			EZz5MPmzAgMBAAECggEAPTIKf6fGnm8BQKdntRTv0O1Bavwa9+Vp+caZ5ycpJa5Y
							// 			Fm1BcLVtBDv+TesrtwXBB5egxGEPWK1Qj7AlfXaiWTbmDSsSK/u5cDzlAPaA18zI
							// 			sNS+ncQruw9hfPv73wnee1fuVsNe1wAgyNqbO6kSlcqFggnAIMcDIsT82XTjz4+N
							// 			of6sJxQfCwSOR3WKV4r+9F4KXPgre+0wm5aNSQhW1KfV1r918DtHjcDxtvOZn7PB
							// 			GFj/xx3UacZdDOfauqZSMf4ZghCHBCBH/LOVmk3hqEokHHdzP36dm6/CkVoK+sbF
							// 			FYCNlD/t1FUShXbEh+iHnSPbA51Vo5f1+OPKlW99AQKBgQDSJFcWLXuW8DIyz+UN
							// 			5ZL++nFkSWyAShACeOC81fk6wEiatmbmAa0Qs6OcAJuYDeRwt47FX9fsNvm9hud8
							// 			BueYNPmmC0mhO1PSRWQCKDghY+F0/nSV8QB44pR5o7m2yV+B/Pyg12qbBOTg3NLY
							// 			yKYpaxwcDFWEEmRLusAZCLizcwKBgQDH/Zf4W58yUTzK/l3iY4luYZBDMjA5/yFv
							// 			kndQxqsGpzS6KQtOCS5RLhC+1176h8lNy7NdNqca6x15QJ2UhqUOeFVcqbatjaL2
							// 			bv4gro4j2nVOgKmR03fto7s3BKtPHlFPON//R28bWmPm+ap/S/aWS6doNQpOCqW1
							// 			mLKI5LuQwQKBgGbbXrz+OjYhD5ELbSQmMJMZZpMd1TveBIQRQn9rhHgbUe5YRXlj
							// 			bKB2LSjYq0/7zMrXLcyyIu/94LPB6mAsyQMZOvDpKXr/nQGY8WCU6xR83Qf03H/f
							// 			3MlOrjnzx50OZ+8qM0VO62FBPf5KV/HAFITFZpbb+qeQkQL4P7qBKFa9AoGBAKal
							// 			aAbpweQZ0YCNKQpGSvSRk7aKkakiMWhZMdc7VLP8jHE7VlI2UEQREJ8Vs+0rTNDo
							// 			lpNrwR8rH6oz75sd/1fpaagHO1OvHEYhAt2U1piFpw49JA+BmQOKVaxo1Z7d8n8D
							// 			M5PyoGC4l1qWXD4qvFVMwTiSSf3x3VdO4CY2Ax2BAoGATYQfX/vxk6v7gVr4fBQU
							// 			jCd25kxrhQ5GZ1tvL8HND/pz3o1qu5stGAhoM7t2+w6/OxwDCBluKwYx9fcaP1tI
							// 			vA9ebRwGmUQTojjPwQMNfbuQdD1xIq+C6fKg0cSCvRfwDQxXTsjJgpE6Qhs9LygL
							// 			E7Tysgyd8jjH5lEj8r3qCSU=-----END PRIVATE KEY-----`
							
							// 	// 加签
							// 	var sign_rsa = new RSA.RSAKey();
							// 	sign_rsa = RSA.KEYUTIL.getKey(sikey);
							// 	var hashAlg = 'sha256';
							// 	var hSig = sign_rsa.signString(paySign, hashAlg);
							// 	hSig = RSA.hex2b64(hSig); // hex 转 b64
							// 	uni.hideLoading();
							let payList=res.body
							let data = res.body;
							uni.hideLoading();
							wx.requestPayment({
								appId: payList.appid,
								nonceStr: payList.noncestr,
								package: payList.package,
								signType: 'RSA',
								timeStamp: payList.timestamp,
								paySign:payList.sign,
								success: function(res) {
									uni.hideLoading();
									uni.showToast({
										title: '微信支付成功'
									});
									setTimeout(function() {
										uni.redirectTo({
											url: '/pages/money/paySuccess'
										})
									}, 600);
								},
								fail: function(err) {
									uni.hideLoading();
									uni.showModal({
										title: '支付失败',
										content: '订单支付失败，请重新进行支付。如对订单金额有疑问请联系客服人员',
										showCancel: false
									});
									return;
								}
							});
						}
					})
				})
				
			},
		}
	}
</script>

<style lang='scss'>
	.app {
		width: 100%;
	}

	.price-box {
		background-color: #fff;
		height: 265upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #909399;

		.price{
			font-size: 50upx;
			color: #303133;
			margin-top: 12upx;
			&:before{
				content: '￥';
				font-size: 40upx;
			}
		}
	}

	.pay-type-list {
		margin-top: 20upx;
		background-color: #fff;
		padding-left: 60upx;
		
		.type-item{
			height: 120upx;
			padding: 20upx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-right: 60upx;
			font-size: 30upx;
			position:relative;
		}
		
		.icon{
			width: 100upx;
			font-size: 52upx;
		}
		.icon-erjiye-yucunkuan {
			color: #fe8e2e;
		}
		.icon-weixinzhifu {
			color: #36cb59;
		}
		.icon-alipay {
			color: #01aaef;
		}
		.tit{
			font-size: 26rpx;
			color: #01aaef;
			margin-bottom: 4upx;
		}
		.con{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: 26rpx;
			color: $uni-text-color;
		}
	}
	.mix-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 630upx;
		height: 80upx;
		margin: 80upx auto 30upx;
		font-size: 26rpx;
		color: #fff;
		background-color: #ff633d;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}

</style>
